import 'package:ft_reader/beans/book_info_bean.dart';
import 'package:ft_reader/blocs/base_bloc.dart';
import 'package:rxdart/rxdart.dart';

class BookInfoBloc extends BaseBloc {

  final _bookInfoFetcher = PublishSubject<BookInfoBean>();

  final _bookAddStateFetcher = PublishSubject<bool>();

  // 监听
  Observable<BookInfoBean> get bookInfoData => _bookInfoFetcher.stream;

  Observable<bool> get addStoreSate => _bookAddStateFetcher.stream;

  void fetchBookInfo (int bookId) async {
    BookInfoBean bookInfoBean = await netApi.fetchBookInfoData(bookId);
    if (!_bookInfoFetcher.isClosed) {
      _bookInfoFetcher.sink.add(bookInfoBean);
    }
  }

  void changeAddState(bool value) {
    if (!_bookAddStateFetcher.isClosed) {
      _bookAddStateFetcher.sink.add(value);
    }
  }


  @override
  void dispose() {
    // TODO: implement dispose
    super.dispose();
    _bookInfoFetcher?.close();
    _bookAddStateFetcher?.close();
  }
}